package com.software.backend.center.service;

import com.software.backend.center.repository.UserExtnendsRepository;
import com.software.backend.login.entity.UserExtends;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @program: back-end
 * @description:
 * @author: C@t
 * @create: 2022-12-24 10:51
 **/
@Service
public class UserExtendsServiceImpl implements UserExtendsService {
    @Autowired
    private UserExtnendsRepository userExtnendsRepository;
    @Override
    public UserExtends findById(Long id) {
        Optional<UserExtends> optional = userExtnendsRepository.findById(id);
        return optional.get();
    }

    @Override
    public UserExtends updateUserExtends(UserExtends userExtends) {
        UserExtends save = userExtnendsRepository.save(userExtends);
        return save;
    }

    @Override
    public String getAvatarUrlById(Long id) {
        Optional<UserExtends> avaterUrlById = userExtnendsRepository.findUserExtendsById(id);
        if (avaterUrlById.isPresent()){
            return avaterUrlById.get().getAvatarUrl();
        }else {
            return null;
        }
    }
}
